package com.iptv.grape.bu.imp;

import android.view.KeyEvent;

import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.AppState;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.bu.IKeyEventPorc;
import com.iptv.grape.domain.Channel;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.data.LiveData;
import com.iptv.grape.util.AppConstant;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;

import static com.iptv.grape.bu.GrapeContext.curGrapeContext;

// 退出回看模式 切换为当前的直播
@AppState(isShowLiveMenu = false,isShowChannelBillUI = false, curLiveType="Back",keyVals = {4})
public class QuitBackMode implements IKeyEventPorc {
    @Override
    public void onKeyDownEvent(BaseActivity context, XMediaPlayer mediaPlayer, GrapeContext grapeContext, KeyEvent event) {
        //grapeContext.loadChannelBillUI(context,null,null);
        execQuitBackMode(context);

    }

    public static void execQuitBackMode(BaseActivity context){
        GrapeContext.curGrapeContext().setCurPlayType("Live");
        GrapeContext.curGrapeContext().setCurLiveType("Live");
        GrapeContext.curGrapeContext().removeChannelBillUI(context);
        Channel channel = GrapeContext.curGrapeContext().getChannelDLinkList().getCurChannel();
        channel.playChannel();

        LiveData liveData = new LiveData(channel, "6", "23", "0");
        EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition, liveData));
    }

    public static void execQuitBackMode(BaseActivity context,Channel toChannel){
        GrapeContext.curGrapeContext().setCurPlayType("Live");
        GrapeContext.curGrapeContext().setCurLiveType("Live");
        GrapeContext.curGrapeContext().removeChannelBillUI(context);
        Channel channel =GrapeContext.curGrapeContext().getChannelDLinkList().getCurChannel();
        if(toChannel!=null) {
            channel= toChannel;
        }
        channel.playChannel();
        LiveData liveData = new LiveData(channel, "6", "23", "0");
        EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition, liveData));
    }
}
